package member;

import javax.swing.JTextField;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.PlainDocument;


class LimitedJTextField extends PlainDocument {
	private int limit;
	
	private boolean toUppercase = false;
	LimitedJTextField(int limit){
		super();
		this.limit = limit;
	}
	LimitedJTextField(int limit, boolean upper){
		super();
		this.limit = limit;
		this.toUppercase = upper;
	}
	public void insertString
		(int offset, String str, AttributeSet attr) throws BadLocationException{
			if(str == null){
				return;
			}
			if ( (getLength()+str.length())<=limit){
				if(toUppercase){
					str = str.toUpperCase();
				}
				super.insertString(offset, str, attr);
			}
	}
}